package com.example.ivory.accountbook.packetActivity;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.ivory.accountbook.R;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by 王如梦 on 2016/8/29.
 * 添加账户界面listview的适配器
 */

public class AddAdapter extends BaseAdapter {
    //Activity 上下文对象
    private Context context=null;

    //listview添加的内容,有Map<"logo",>  Map<"type">
    private List<Map<String,Object>> listDate=new ArrayList<Map<String,Object>>();

    //构造函数，赋值对应的两个参数
    public AddAdapter(Context contexts,List<Map<String,Object>>list ){
        this.context=contexts;
        listDate=list;
    }

    @Override
    public int getCount() {
        return listDate.size();
    }

    @Override
    public Object getItem(int i) {
        return listDate.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        //通过赋值的context创建布局资源管理器
        LayoutInflater layoutInflater=LayoutInflater.from(context);
        //加载布局资源文件
        view=layoutInflater.inflate(R.layout.activity_additems,null);
        ImageView image= (ImageView) view.findViewById(R.id.imageviewPacketLogo);
        TextView txtType= (TextView) view.findViewById(R.id.textviewPacketType);
        
        txtType.setText(listDate.get(i).get("type").toString());

        switch(listDate.get(i).get("logo").toString()){
            case "cash":
                image.setImageResource(R.drawable.user);
                break;
            case "cashcard":
                image.setImageResource(R.drawable.user);
                break;
            case "creditcard":
                image.setImageResource(R.drawable.user);
                break;
            case "webaccount":
                image.setImageResource(R.drawable.user);
                break;
            case "investment":
                image.setImageResource(R.drawable.user);
                break;
            case "collectaccount":
                image.setImageResource(R.drawable.user);
                break;
            case "payaccount":
                image.setImageResource(R.drawable.user);
                break;
        }
        return view;
    }
}
